package com.threeox.commonlibrary.ui.view.multipagenavigation;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.Button;
import android.widget.LinearLayout;

import com.threeox.commonlibrary.entity.engine.model.multipage.PageDataMessage;
import com.threeox.commonlibrary.ui.view.inter.engine.multipage.INavigationIndicatorView;

/**
 * 
 * @ClassName: CommonButtonIndicatorView
 * 
 * @Description: TODO(自定义LinearLayout滑动指示器子View)
 * 
 * @author 赵屈犇
 * 
 * @date 创建时间: 2017/8/10 18:37
 * 
 * @version 1.0
 * 
 */
public class CommonButtonIndicatorView extends Button implements INavigationIndicatorView {

    public CommonButtonIndicatorView(Context context) {
        this(context, null);
    }

    public CommonButtonIndicatorView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CommonButtonIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.weight = 1;
        params.topMargin = 10;
        params.bottomMargin = 8;
        setLayoutParams(params);
        setTextSize(12);
        setPadding(10, 7, 10, 10);
        setBackground(null);
        setCompoundDrawablePadding(10);
        setGravity(Gravity.CENTER);
    }

    @Override
    public INavigationIndicatorView setPageDataMessage(PageDataMessage data) {
        try {
            if (data.getIconId() != null) {
                Drawable top = getResources().getDrawable(data.getIconId());
                setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
            }
            if (data.getNavBgId() != null) {
                setTextColor(getResources().getColorStateList(data.getNavBgId()));
            }
            setText(data.getTitle());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this;
    }

}
